package vtc;

import java.util.concurrent.*;
import java.util.*;

public class StrategyUnitExample extends FunctionalUnit
{
	StrategyUnitExample(String id, VtcArrayBlockingQueue inQueues[], VtcArrayBlockingQueue outQueues[])
	{
		super(id, inQueues, outQueues);
	}
	
	public void functionalProcess() throws InterruptedException
	{
		Object [] eventv;
		try
		{
			eventv = (Object [])inValue_.getEvent();
		}
		catch(Exception e)
		{
			System.out.print("Input event in StrategyUnitExample not an Object[].");
			return;
		}
		Date timeTag = inValue_.getTimeTag();
		Double price = (Double)eventv[0];
		Double ema = (Double)eventv[1];
		String transition = "buy";
		if(ema <= price)
		{
			transition ="sell";
		}
		Object [] newEventv = new Object[3];
		newEventv[0] = transition;
		newEventv[1] = price;
		newEventv[2] = ema;
		//System.out.print("Transition proposed: " + transition + "\n");
		outValue_ = new VtcTimeTaggedEvent(newEventv, timeTag);
	}
}